/**
    业务受理-业主账户明细
**/
(function(vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            simplifyAccountDetailManageInfo: {
                accountDetails: [],
                shopAccounts: [],
                total: 0,
                records: 1,
                moreCondition: false,
                scId: '',
                ownerId:'',
                conditions: {
                    acctId: '',
                    detailType: '',
                    orderId: '',
                    objId:'',
                }
            }
        },
        _initMethod: function() {
            $that.simplifyAccountDetailManageInfo.conditions.acctId = vc.getParam('acctId');
            $that.simplifyAccountDetailManageInfo.conditions.objId = vc.getParam('ownerId');
            $that.simplifyAccountDetailManageInfo.ownerId= vc.getParam('ownerId');
            vc.component._listAccountDetails(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function() {

            vc.on('simplifyAccountDetailManage', 'switch', function (_param) {
                if (_param.acctId == '') {
                    return;
                }
                $that.simplifyAccountDetailManageInfo.conditions.acctId = _param.acctId;
                $that.simplifyAccountDetailManageInfo.conditions.objId = _param.ownerId;
                $that.simplifyAccountDetailManageInfo.ownerId=  _param.ownerId;
                vc.copyObject(_param, $that.simplifyAccountDetailManageInfo)
                vc.component._listAccountDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            });

            vc.on('simplifyAccountDetailManage', 'listAccountDetail', function(_param) {
                vc.component._listAccountDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            // vc.on('pagination', 'page_event', function(_currentPage) {
            //     vc.component._listAccountDetails(_currentPage, DEFAULT_ROWS);
            // });

            vc.on('simplifyAccountDetailManage', 'refresh', function () {
                vc.component._listAccountDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            });
        },
        methods: {
            _listAccountDetails: function(_page, _rows) {
                if($that.simplifyAccountDetailManageInfo.conditions.objId ==''){
                    return ; 
                }
                vc.component.simplifyAccountDetailManageInfo.conditions.page = _page;
                vc.component.simplifyAccountDetailManageInfo.conditions.row = _rows;
                var param = {
                    params: vc.component.simplifyAccountDetailManageInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/account/queryOwnerAccountDetail',
                    param,
                    function(json, res) {
                        var _simplifyAccountDetailManageInfo = JSON.parse(json);
                        vc.component.simplifyAccountDetailManageInfo.total = _simplifyAccountDetailManageInfo.total;
                        vc.component.simplifyAccountDetailManageInfo.records = _simplifyAccountDetailManageInfo.records;
                        vc.component.simplifyAccountDetailManageInfo.accountDetails = _simplifyAccountDetailManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: vc.component.simplifyAccountDetailManageInfo.records,
                            dataCount: vc.component.simplifyAccountDetailManageInfo.total,
                            currentPage: _page
                        });
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _queryAccountDetailMethod: function() {
                vc.component._listAccountDetails(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function() {
                if (vc.component.simplifyAccountDetailManageInfo.moreCondition) {
                    vc.component.simplifyAccountDetailManageInfo.moreCondition = false;
                } else {
                    vc.component.simplifyAccountDetailManageInfo.moreCondition = true;
                }
            },
            //预存
            _prestoreAccount: function () {
                vc.emit('prestoreAccountDeposit', 'openAddModalWithParams', $that.simplifyAccountDetailManageInfo)
            },
            _cancelAccountDetail: function(_detail) {
                vc.emit('cancelAccountDetail', 'openAddModal', _detail);
            },
            _refundAccount: function() {
                // vc.goBack();
                vc.emit('prestoreAccountRefund', 'openAddModalWithParams', $that.simplifyAccountDetailManageInfo)
            },
            //冻结
            _accountFreeze: function () {
                let _data = {
                acctId:  $that.simplifyAccountDetailManageInfo.conditions.acctId,
                    freeze: "1"
                }
                vc.http.apiPost(
                '/account/updateAccount',
                JSON.stringify(_data), {
                    emulateJSON: true
                },
                function(json, res) {
                    let _json = JSON.parse(json);
                    if (_json.code == 0) {
                        //关闭model
                        vc.component._listAccounts(DEFAULT_PAGE, DEFAULT_ROWS);
                        vc.toast('冻结成功');
                        return;
                    }
                    vc.message(_json.msg);

                },
                function(errInfo, error) {
                    console.log('请求失败处理');

                    vc.message(errInfo);

                });

            },
            //取消冻结
            _accountUnFreeze: function () {
                let _data = {
                    acctId:  $that.simplifyAccountDetailManageInfo.conditions.acctId,
                        freeze: "0"
                    }
                    vc.http.apiPost(
                    '/account/updateAccount',
                    JSON.stringify(_data), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.component._listAccounts(DEFAULT_PAGE, DEFAULT_ROWS);
                            vc.toast('取消冻结成功');
                            return;
                        }
                        vc.message(_json.msg);

                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');

                        vc.message(errInfo);

                    });
            }

        }
    });
})(window.vc);